package com.yljk.yljkproject.ui;

import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.alsk.rn.common.util.RNDebugUtils;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.WritableMap;
import com.yilijk.base.utils.ToastUtils;
import com.yljk.servicemanager.constants.ReactApi;
import com.yljk.servicemanager.oldbase.ModuleBaseActivity;
import com.yljk.yljkproject.MyActivityManager;
import com.yljk.yljkproject.R;
import com.yljk.yljkproject.utils.PushMessageUtil;
import com.yljk.yljkproject.utils.ReactUtils;
import com.yljk.yljkproject.view.pickview.PickerView;

public class RNDebugActivity extends ModuleBaseActivity {

    private String IP = "";
    private String NO = "";
    private TextView ip;
    private TextView no;

    TextView pageName;

    @Override
    public int bondLayout() {
        return R.layout.activity_rndebug;
    }

    @Override
    public void initView() {
        TextView titleName = (TextView) findViewById(R.id.webviewtitle);
        titleName.setText("react-native setting debug");
        ip = (TextView) findViewById(R.id.rndebug_ip);
        no = (TextView) findViewById(R.id.rndebug_no);

        pageName = (TextView) findViewById(R.id.rndebug_page);
        findViewById(R.id.web_back).setOnClickListener(v -> finish());
    }

    @Override
    public void initData() {

    }

    @Override
    public void initEvent() {
        findViewById(R.id.rndebug_login).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getIP();
                settingDebug(ReactApi.LOGIN_DOCTORBUNDLE);
            }
        });
        findViewById(R.id.rndebug_home).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getIP();
                settingDebug(ReactApi.HOME_DOCTORBUNDLE);
            }
        });
        findViewById(R.id.rndebug_message).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getIP();
                settingDebug(ReactApi.IM_DOCTORBUNDLE);
            }
        });
        findViewById(R.id.rndebug_mine).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getIP();
                settingDebug(ReactApi.MY_DOCTORBUNDLE);
            }
        });
        findViewById(R.id.rndebug_Closeing_All).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RNDebugUtils.RNDebugModel debugModule = new RNDebugUtils.RNDebugModel(ReactApi.LOGIN_DOCTORBUNDLE, IP + ":" + NO, false);
                RNDebugUtils.setDebugStatus(RNDebugActivity.this, debugModule);
                RNDebugUtils.RNDebugModel debugModule1 = new RNDebugUtils.RNDebugModel(ReactApi.HOME_DOCTORBUNDLE, IP + ":" + NO, false);
                RNDebugUtils.setDebugStatus(RNDebugActivity.this, debugModule1);
                RNDebugUtils.RNDebugModel debugModule2 = new RNDebugUtils.RNDebugModel(ReactApi.IM_DOCTORBUNDLE, IP + ":" + NO, false);
                RNDebugUtils.setDebugStatus(RNDebugActivity.this, debugModule2);
                RNDebugUtils.RNDebugModel debugModule4 = new RNDebugUtils.RNDebugModel(ReactApi.MY_DOCTORBUNDLE, IP + ":" + NO, false);
                RNDebugUtils.setDebugStatus(RNDebugActivity.this, debugModule4);
                finish();
            }
        });

        findViewById(R.id.rndebug_open1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ReactUtils.INSTANCE.push(RNDebugActivity.this, ReactApi.LOGIN_DOCTORBUNDLE, pageName.getText().toString().trim());
            }
        });
        findViewById(R.id.rndebug_open2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ReactUtils.INSTANCE.push(RNDebugActivity.this, ReactApi.HOME_DOCTORBUNDLE, pageName.getText().toString().trim());
            }
        });
        findViewById(R.id.rndebug_open3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ReactUtils.INSTANCE.push(RNDebugActivity.this, ReactApi.IM_DOCTORBUNDLE, pageName.getText().toString().trim());
            }
        });
        findViewById(R.id.rndebug_open5).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ReactUtils.INSTANCE.push(RNDebugActivity.this, ReactApi.MY_DOCTORBUNDLE, pageName.getText().toString().trim());
            }
        });
        findViewById(R.id.android_pickview).setOnClickListener(v -> {
            PickerView.getInstance(MyActivityManager.getInstance().getCurrentActivity()).getPicker(null, MyActivityManager.getInstance().getCurrentActivity(), new Promise() {
                @Override
                public void resolve(@Nullable Object value) {
                    ToastUtils.showShort(value.toString());
                }

                @Override
                public void reject(String code, String message) {

                }

                @Override
                public void reject(String code, Throwable throwable) {

                }

                @Override
                public void reject(String code, String message, Throwable throwable) {

                }

                @Override
                public void reject(Throwable throwable) {

                }

                @Override
                public void reject(Throwable throwable, WritableMap userInfo) {

                }

                @Override
                public void reject(String code, @NonNull WritableMap userInfo) {

                }

                @Override
                public void reject(String code, Throwable throwable, WritableMap userInfo) {

                }

                @Override
                public void reject(String code, String message, @NonNull WritableMap userInfo) {

                }

                @Override
                public void reject(String code, String message, Throwable throwable, WritableMap userInfo) {

                }

                @Override
                public void reject(String message) {

                }
            });
        });
        findViewById(R.id.debug_scheme_test).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String schemeStr = "com.doctor.scheme://general?module=native&page=MessageList&url=111&doctorId2=222&doctorId3=333&doctorId4=444";
                PushMessageUtil.getInstance().dealMessage(RNDebugActivity.this,schemeStr,false);
//
//                String schemeStr = "com.doctor.scheme://general?module=native&page=MyPhysicianVisits&doctorId1=111&doctorId2=222&doctorId3=333&doctorId4=444";
//                PushMessageUtil.getInstance().dealMessage(RNDebugActivity.this, schemeStr, false);
//
            }
        });

    }

    void getIP() {
        IP = ip.getText().toString().trim();
        NO = no.getText().toString().trim();
    }

    void settingDebug(String react_native_module_name) {
        RNDebugUtils.RNDebugModel debugModule = new RNDebugUtils.RNDebugModel(react_native_module_name, IP + ":" + NO, true);
        RNDebugUtils.setDebugStatus(RNDebugActivity.this, debugModule);
        Toast.makeText(this, react_native_module_name + "调试设置成功", Toast.LENGTH_SHORT).show();
        finish();
    }
}